package com.hydong.novatest.activity

import android.content.res.Configuration
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.hydong.novatest.R
import com.hydong.novatest.Utils.QDSkinManager
import com.hydong.novatest.base.BaseActivity
import com.qmuiteam.qmui.skin.QMUISkinManager
import com.qmuiteam.qmui.util.QMUIStatusBarHelper
import kotlinx.android.synthetic.main.activity_about.*

class HomeActivity : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val skinManager = QMUISkinManager.defaultInstance(this)
        setSkinManager(skinManager)
        mOnSkinChangeListener.onSkinChange(skinManager, -1, skinManager.currentSkin)

        val root: View = LayoutInflater.from(this).inflate(R.layout.activity_home, null)
        setContentView(root)

        initView()
    }

    private fun initView() {
        topbar?.setTitle(getString(R.string.app_name))
        topbar?.addLeftBackImageButton()?.setOnClickListener {
            popBackStack()
        }

    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
    }

    override fun onStart() {
        super.onStart()
        skinManager?.addSkinChangeListener(mOnSkinChangeListener)
    }

    override fun onStop() {
        super.onStop()
        skinManager?.removeSkinChangeListener(mOnSkinChangeListener)
    }

    private val mOnSkinChangeListener = QMUISkinManager.OnSkinChangeListener { skinManager, oldSkin, newSkin ->
        if (newSkin == QDSkinManager.SKIN_WHITE) {
            QMUIStatusBarHelper.setStatusBarLightMode(this)
        } else {
            QMUIStatusBarHelper.setStatusBarDarkMode(this)
        }
    }
}